package com.padbot.qm.security;

public class UserSessionTokenUtils {

	public UserSessionTokenUtils() {
	}

	public static boolean isActive(String token){
		UserSessionBean userSessionBean = UserSessionContainer.getInstance().get(token);
		if(userSessionBean == null){
			return false;
		}
		UserSessionToken userSessionToken = userSessionBean.getToken();
		if(userSessionToken == null){
			return false;
		}
		return userSessionToken.isActive();
	}
	
	public static UserSessionBean setUserSession(String userId, String username, String nickName){
		UserSessionBean userSessionBean = UserSessionTokenFactory.createToken(userId, username, nickName);
		UserSessionContainer.getInstance().put(userSessionBean.getTokenKey(), userSessionBean);
		return userSessionBean;
	}
	
	public static void removeUserSession(String token){
		UserSessionContainer.getInstance().remove(token);
	}
}
